Skip to content

refactor: V1Trap derives from PDU, not the v2 Trap - #31

Merged
stakach merged 1 commit into
spider-gazelle:masterfrom
n-rodriguez:fix/v1trap-hierarchy
Jul 13, 2026
Merged

refactor: V1Trap derives from PDU, not the v2 Trap#31
stakach merged 1 commit into
spider-gazelle:masterfrom
n-rodriguez:fix/v1trap-hierarchy

Conversation

@n-rodriguez

Copy link
Copy Markdown
Contributor

The final audit item (#7) — previously deferred, brought forward since it is a breaking change and belongs before 1.0 (afterwards it would cost a major).

Problem

V1Trap < Trap < PDU, but an RFC 1157 trap is its own variant of the protocol's PDU CHOICE, not an SNMPv2 trap (Liskov violation):

  • Trap#oid means snmpTrapOID; V1Trap#oid silently meant the enterprise OID — same accessor, different meaning.
  • V1Trap dragged in v2 trap semantics that do not exist on the v1 wire, and its parse constructor re-initialised every inherited field.

Change

  • V1Trap now derives from PDU directly (a v1 Trap-PDU is a PDU — it carries varbinds and flows through Message — it just isn't a v2 trap). The Message#pdu union and all its proxies are untouched.
  • Own enterprise / time_ticks properties; #oid gets its standard PDU meaning back (first varbind's OID).
  • The v2-style request-id / error fields inherited from PDU have no meaning in v1 and stay at their defaults — documented as the deliberate trade-off for keeping the shared PDU interface.
  • Session#trap_v1 passes enterprise: (was oid:).

Warning

Breaking (pre-1.0): V1Trap#oid now returns the first varbind's OID — use #enterprise for the enterprise OID; v1trap.is_a?(Trap) is now false.

Tests

New v1_trap_spec (not-a-Trap, enterprise vs oid); snmp_spec asserts both accessors against a real captured trap; the v1 build→parse round-trip (notifications_spec) still passes. Deterministic 94/94, multi-threaded 94/94, legacy 3/3, ameba clean, format clean.

With this merged the audit (#7) is complete: 64/64.

🤖 Generated with Claude Code

An RFC 1157 trap is its own variant of the protocol's PDU CHOICE, not an SNMPv2
trap: inheriting Trap silently redefined #oid to mean the enterprise OID and
dragged in v2 trap semantics that do not exist on the v1 wire (Liskov).

- v1_trap: derive from PDU; own enterprise / time_ticks properties; #oid gets
  its standard PDU meaning back (first varbind). The v2-style request-id /
  error fields inherited from PDU stay at their defaults, documented as such
- session: trap_v1 passes enterprise: (was oid:)
- spec: v1_trap_spec (not-a-Trap, enterprise vs oid); snmp_spec asserts both
  accessors on a real captured trap; notifications_spec updated

BREAKING: V1Trap#oid now returns the first varbind's OID (use #enterprise for
the enterprise); V1Trap no longer is_a?(Trap).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@stakach
stakach merged commit 94e9ca3 into spider-gazelle:master Jul 13, 2026
6 checks passed
@n-rodriguez
n-rodriguez deleted the fix/v1trap-hierarchy branch July 21, 2026 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants